package com.ay.selfservicemachine.base;


import java.lang.ref.WeakReference;

//import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
//import io.reactivex.rxjava3.core.Observable;

@SuppressWarnings("unused")
public abstract class Module<P extends IContract.IPresenter> {

    private WeakReference<P> dataCallback;

    public Module() {
    }

    protected P getDataCallback() {
        return dataCallback.get();
    }

    public void attachPresenter(P p) {
        dataCallback = new WeakReference<>(p);
    }

//    public <T> Observable<T> dataChangedObservable(T t) {
//        return Observable.just(t)
//                .observeOn(AndroidSchedulers.mainThread());
//    }
//
//    public  <T> Observable<T> dataChangedObservable(Observable<T> observable) {
//        return observable
//                .observeOn(AndroidSchedulers.mainThread());
//    }


    public void detachPresenter() {
        if (dataCallback != null) {
            dataCallback.clear();
//            dataCallback = null;
        }
    }
}
